<?php
	//include 'conn.php';
	header("Content-type:text/html;charset=utf-8");
	$db = new mysqli("210.45.241.240","root","","trenchmonitorday");
	if(!$db)
		die("error connect to mysql");
	$db->query("set names utf8");

	$sql ="select * from dipangleday"; //SQL
	$result = $db->query($sql);

	$json ="";
	$data =array(); //定义好一个数组.PHP中array相当于一个数据字典.
	
	//定义一个类,用到存放从数据库中取出的数据.
	class User 
	{
	public $device_name ;
	public $device_ID;
	public $dataX;
	public $dataY;
	public $local_date;
	}
	//
	while ($row= $result->fetch_assoc())
	{
	$user =new User();
	$user->device_name = "倾斜角";
	$user->device_ID = "01";
	$user->dataX = $row["dipangleday"];
	$user->dataY = $row["dipangleday"]-80;
	$user->local_date = $row["BDTime"];
	$data[]=$user;
	}
	$json = json_encode($data);//把数据转换为JSON数据.
	$json_data = "{".'"user"'.":".$json."}";
	echo $json_data;
	//echo "{".'"user"'.":".$json."}";
?>